﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using Cloak.NUnit;
using Cloak.Reflection;
using NUnit.Framework;

namespace Ruleweaver.Rules
{
	public class CreateMethodRule : Behavior
	{
		private CheckRule _rule;
		private MethodInfo _method;
		private MemberRule _methodRule;

		protected override void Given()
		{
			_rule = Rule.Check(Reflect.Func<ICheckable<int>, Check<int>>(Checkable.IsPositive));

			_method = typeof(TestTarget).GetMethod("Foo");
		}

		protected override void When()
		{
			_methodRule = Rule.Method(_method, _rule);
		}

		[Then]
		public void MemberIsMethod()
		{
			Assert.AreEqual(_method, _methodRule.Member);
		}

		[Then]
		public void MemberTypeIsReturnType()
		{
			Assert.AreEqual(typeof(int), _methodRule.MemberType);
		}

		[Then]
		public void RuleIsOriginal()
		{
			Assert.AreEqual(_rule, _methodRule.Rule);
		}

		[Then]
		public void HasMethodType()
		{
			Assert.AreEqual(RuleType.Method, _methodRule.Type);
		}

		private sealed class TestTarget
		{
			public int Foo()
			{
				return 1;
			}
		}
	}
}